<template>
   
  <el-card class="form-container" shadow="never">
    <el-form
      :model="member"
      :rules="rules"
      ref="memberFrom"
      label-width="150px"
    >
      <el-form-item label="用户昵称：" prop="nickname">
        <el-input v-model="member.nickname"></el-input>
      </el-form-item>
      <el-form-item label="用户手机：" prop="phone">
        <el-input v-model="member.phone"></el-input>
      </el-form-item>
      <el-form-item label="是否精简VIP：" prop="isVip">
        <el-radio-group v-model="member.isVip">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否考前VIP：" prop="isVip">
        <el-radio-group v-model="member.isKaoqian">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否新规VIP：" prop="isVip">
        <el-radio-group v-model="member.isXingui">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否地方题库VIP：" prop="isVip">
        <el-radio-group v-model="member.isDifang">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="佣金：" prop="commission">
        <el-input v-model="member.commission"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('memberFrom')"
          >提交</el-button
        >
        <el-button v-if="!isEdit" @click="resetForm('memberFrom')"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
import { createMember, getMember, updateMember } from "@/api/ums/member";
const defaultMember = {
  id: "",
  nickname: "",
  phone: 0,
  commission: "",
};
export default {
  name: "MemberDetail",
  components: {},
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      member: Object.assign({}, defaultMember),
      rules: {
        nickname: [
          { required: true, message: "请输入品牌名称", trigger: "blur" }
          // {
          //   min: 2,
          //   max: 140,
          //   message: "长度在 2 到 140 个字符",
          //   trigger: "blur",
          // },
        ],
        phone: [{ required: true, message: "请输入品牌logo", trigger: "blur" }]
      },
    };
  },
  created() {
    if (this.isEdit) {
      getMember(this.$route.query.id).then((response) => {
        this.member = response.data;
      });
    } else {
      this.member = Object.assign({}, defaultMember);
    }
  },
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm("是否提交数据", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            if (this.isEdit) {
              updateMember(this.$route.query.id, this.member).then((response) => {
                this.$refs[formName].resetFields();
                this.$message({
                  message: "修改成功",
                  type: "success",
                  duration: 1000,
                });
                this.$router.back();
              });
            } else {
              createMember(this.member).then((response) => {
                this.$refs[formName].resetFields();
                this.member = Object.assign({}, defaultMember);
                this.$message({
                  message: "提交成功",
                  type: "success",
                  duration: 1000,
                });
              });
            }
          });
        } else {
          this.$message({
            message: "验证失败",
            type: "error",
            duration: 1000,
          });
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.member = Object.assign({}, defaultMember);
    },
  },
};
</script>
<style>
</style>


